"""Data declarations for the choosegame datastore

Each of the classes defined in this file represents one of the entites
in the application datastore.
"""
from google.appengine.ext import db

# just the super basics here. This is the data structure we use to
# store individual game entries. For now, we're going to just do it
# naively per user.
class GameEntry(db.Model):
  bgguser = db.StringProperty()
  name = db.StringProperty()
  bggid = db.IntegerProperty(default = 0)
  my_rating = db.FloatProperty()
  bgg_average = db.FloatProperty()
  weight = db.FloatProperty()
  min_players = db.IntegerProperty()
  max_players = db.IntegerProperty()
  playing_time = db.IntegerProperty()
  num_plays = db.IntegerProperty()
  best_with = db.ListProperty(long)
  rec_with = db.ListProperty(long)

# this is where we simply store an entire chunk of data, uninterpreted, so
# we can read it via streaming services later.
#
# We'll actually cut down the CSV file data so that it only contains the bits
# we need.
class GameChunk(db.Model):
  bgguser = db.StringProperty()
  bggid = db.IntegerProperty(default = 0)
  created = db.DateTimeProperty(auto_now_add = True)
  updated = db.DateTimeProperty(auto_now = True)
  format = db.StringProperty(default = "csv")
  csvdata = db.TextProperty()

# And here's where we can store metadata about the collection properties.
class CollectionEntry(db.Model):
  bgguser = db.StringProperty()
  size = db.IntegerProperty()
  num_fetches = db.IntegerProperty(default = 0)
  created = db.DateTimeProperty(auto_now_add = True)
  last_updated = db.DateTimeProperty(auto_now = True)
  update_key = db.StringProperty()

# We'll record people trying to get an an unknown BGG user's collection here
# for later fetching.
class MissingBGGUser(db.Model):
  bgguser = db.StringProperty()
  created = db.DateTimeProperty(auto_now_add = True)
  last_attempted = db.DateTimeProperty(auto_now = True)

class AccountPreference(db.Model):
  account = db.UserProperty()
  hidden_ids = db.ListProperty(long, default=[])
  displayed_users = db.StringListProperty(default=[])
  choose_count = db.IntegerProperty(default = 0)

# we'll need to houseclean this at some point.
class FetchLogEntry(db.Model):
  bgguser = db.StringProperty()
  date = db.DateTimeProperty(auto_now = True)
  status = db.StringProperty() # "updating" / "done"

# Here's where we record the shared secrets for our various facilities.
class SecretEntry(db.Model):
  facility = db.StringProperty()
  token = db.StringProperty()
  created = db.DateTimeProperty(auto_now_add = True)
  updated = db.DateTimeProperty(auto_now = True)
